import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomSupportingFacilities } from '@/shared/model/room-supporting-facilities.model';
import RoomSupportingFacilitiesService from './room-supporting-facilities.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomSupportingFacilitiesDetails extends Vue {
  @Inject('roomSupportingFacilitiesService') private roomSupportingFacilitiesService: () => RoomSupportingFacilitiesService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomSupportingFacilities: IRoomSupportingFacilities = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomSupportingFacilitiesId) {
        vm.retrieveRoomSupportingFacilities(to.params.roomSupportingFacilitiesId);
      }
    });
  }

  public retrieveRoomSupportingFacilities(roomSupportingFacilitiesId) {
    this.roomSupportingFacilitiesService()
      .find(roomSupportingFacilitiesId)
      .then(res => {
        this.roomSupportingFacilities = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
